const express = require('express')

const app = express()

const cors = require('cors')

app.use(cors())

app.get('/testHack', (req, res) => {
    res.send(req.query.search || '')
})

app.get('/setCookie', (req, res) => {
    console.log(req.query)
    res.send('ok')
})

app.get('/login', (req, res) => {
    global.isLogin = 1
    res.send('ok')
})

app.get('/loginStatus', (req, res) => {
    res.send(Boolean(global.isLogin))
})


app.get('/changeMessage', (req, res) => {
    if (global.isLogin) {
        const { from, to } = req.query
        console.log('from: ', from)
        console.log('to: ', to)
        res.send(`change from ${from} to ${to}`)
    } else {
        res.send('error')
    }
})


app.listen(8081, () => {
    console.log('port 8081 is run')
})